<script type="text/javascript" src="<?php echo JS_DIR; ?>jquery.js"></script>

<form id="formsend" action="<?php echo url('email/testsend'); ?>" method="POST">
	<div style="width:990px; height:300px; margin:auto; margin-top:200px;">
		<dl>
			<dt style="width:90px; float:left;">Send to:</dt>
			<dd style="float:left; width:870px; margin:0;">
				<input type="text" id="sendto" name="sendto" style="width:300px;" />
			</dd>
			
			<dt style="width:90px; float:left;">Sites:</dt>
			<dd style="float:left; width:870px; margin:0;">
				<select id="sites" name="sites">
					<?php if(!empty($sitesArray)):
							foreach($sitesArray as $s): ?>
								<option value="<?php echo $s; ?>" <?php if($site == $s){ echo "selected='selected'"; } ?>><?php echo $s; ?></option>
					<?php 	endforeach;
						  endif; ?>
				</select>
			</dd>
			
			<dt style="width:90px; float:left;">Templates:</dt>
			<dd style="float:left; width:870px; margin:0;">
				<select id="emailtpl" name="emailtpl">
					<?php if(!empty($tpls)):
							foreach($tpls as $tpl): ?>
								<option value="<?php echo $tpl; ?>"><?php echo $tpl; ?></option>
					<?php 	endforeach;
						  endif; ?>
				</select>
			</dd>
			
			<dt style="width:90px; float:left;">&nbsp;</dt>
			<dd>
				<input id="btn" type="button" value="Send" />
			</dd>
			
			<dt style="width:90px; float:left;">&nbsp;</dt>
			<dd>
				<span id='mes' style="color:#F00;"></span>
			</dd>
		</dl>
	</div>
	
<script type="text/javascript">
	$('#btn').click(function(){
		$.ajax({
			type: 'POST',
			url: "<?php echo url('email/testsend'); ?>",
			data: $('#formsend').serialize(),
			success: function(data){
						if(data == '1'){
							$('#mes').html('has sent');
						}else{
							$('#es').html('failed');
						}
					 }
		});
	});

	$('#sites').change(function(){
		var site = $(this).val();
		$.ajax({
			type: 'POST',
			url: "<?php echo url('email/testsend'); ?>",
			data: {site: site, gettpl: 1},
			success: function(data){
						$('#emailtpl').html('');
						$.each(data, function(index, item){
							$('#emailtpl').append("<option value='"+item+"'>"+item+"</option>");
						});
					 },
			dataType: 'json'
		});
	});
</script>
</form>